//
//  CellOfFilm.m
//  王宇先_25_代码约束自定义cell
//
//  Created by 王宇先 on 16/4/13.
//  Copyright © 2016年 王宇先. All rights reserved.
//

#import "CellOfFilm.h"
#import "Masonry.h"

@interface CellOfFilm ()
@property (weak, nonatomic) IBOutlet UILabel *labelOfTitle;
@property (weak, nonatomic) IBOutlet UILabel *labelOfDate;
@property (weak, nonatomic) IBOutlet UILabel *labelOfSummary;
@property (weak, nonatomic) IBOutlet UIImageView *imageOfPic;

@end

@implementation CellOfFilm
#pragma mark - override init
//- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
//    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
//    if (self) {
//        [self layoutSubviews];
//    }
//    return self;
//}
#pragma mark - override layoutSubviews 代码约束子控件

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.imageOfPic.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelOfSummary.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelOfDate.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelOfTitle.translatesAutoresizingMaskIntoConstraints = NO;
    [self.contentView addConstraints:@[
                                      //约束照片顶部
                                      [NSLayoutConstraint constraintWithItem:self.imageOfPic attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10],
                                      //左边
                                      [NSLayoutConstraint constraintWithItem:self.imageOfPic attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10],
                                      //右边
                                      [NSLayoutConstraint constraintWithItem:self.imageOfPic attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100],
                                      //高度
                                      [NSLayoutConstraint constraintWithItem:self.imageOfPic attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:180],
                                     ]];
    //title
//    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView.mas_top).with.offset(20);
//        make.left.equalTo(self.imageOfPic.mas_right).with.offset(20);
//        make.height.mas_equalTo(self.labelOfTitle.mas_height).with.offset(40);
//        make.width.mas_equalTo(self.labelOfTitle.mas_width).with.offset(100);
//        
//    }];
//    [self.contentView addConstraints:@[
//                                       //约束标题顶部
//                                       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:30],
//                                       //左边
//                                       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.imageOfPic attribute:NSLayoutAttributeRight multiplier:1.0 constant:20],
//                                       //宽度
//                                       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:200],
//                                       //高度
//                                       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40],
//                                       ]];
    [self.contentView addConstraints:
     @[
       
       // labelOfTitle 约束 上面
       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10],
       // 左边
       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.imageOfPic attribute:NSLayoutAttributeRight multiplier:1.0 constant:10],
       // 右边
       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20],
       //下边
       [NSLayoutConstraint constraintWithItem:self.labelOfTitle attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:0.5 constant:-40]
       
       
       
       ]];
    //date
    [self.labelOfDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labelOfTitle.mas_bottom).with.offset(20);
        make.left.equalTo(self.imageOfPic.mas_right).with.offset(120);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(80);
    }];
    //summary
    [self.labelOfSummary mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageOfPic.mas_bottom).with.offset(20);
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.right.equalTo(self.contentView.mas_right).with.offset(-20);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(10);
    }];
}




#pragma mark - other
- (void)awakeFromNib {
    // Initialization code
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
